#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""定义战斗机类型"""
import pygame


class Ship():
    """定义战舰属性和方法"""

    def __init__(self, ai_settings, screen):
        """初始化飞船并设置其初始位置"""
        self.screen = screen
        self.ai_settings = ai_settings
        # 加载飞机图片并获取其外接矩形
        self.image = pygame.image.load('images/aircraft.jpg')  # 就是一个 surface
        self.image = pygame.transform.smoothscale(self.image, (60, 48))
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        # 将飞船放在底部中央
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom
        # 移动状态标识
        self.moving_right = False
        self.moving_left = False
        # 在飞船的属性 center中存储小数值
        self.centerx = float(self.rect.centerx)

    def blitme(self):
        """在初始化定义的位置渲染绘图"""
        self.screen.blit(self.image, self.rect)

    def update(self):
        """根据移动状态标识来调整飞船的位置"""
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.centerx += self.ai_settings.ship_speed_factor
        if self.moving_left and self.rect.left > 0:
            self.centerx -= self.ai_settings.ship_speed_factor

        self.rect.centerx = self.centerx

    def center_ship(self):
        """将飞船放在底部中央的函数"""
        self.centerx = self.screen_rect.centerx
